package 第五周;

/**
 * @author xhw
 */

public class 两数相除 {
    public static void main(String[] args) {
        int dived = 10;
        int diver = 3;
        int result = divide(dived, diver);
        System.out.println(result);
    }

    private static int divide(int dived, int diver) {
        // 计算符号位
        boolean negative = (dived < 0) ^ (diver < 0);

        // 将输入转换为正值处理
        long dividendLong = Math.abs((long) dived);
        long divisorLong = Math.abs((long) diver);

        // 计算结果
        int result = 0;
        while (dividendLong >= divisorLong) {
            dividendLong -= divisorLong;
            result++;
        }

        // 根据符号位返回结果
        return negative ? -result : result;
    }

}
